<template>
  <el-row>
    <el-col
      :span="16"
      :offset="4"
      v-for="item in levelList"
      :key="item.levelId"
      class="mb10"
      style="line-height: 36px"
    >
      <el-checkbox style="width: 100px" v-model="item.check" class="fl">{{ item.internalLevelName }}</el-checkbox>
      <el-input
        style="width: 50%"
        v-model.number="item.levelScore"
        class="fl ml20 mr20"
        placeholder="输入等级对应分数"
      />
      <p>
        评价理由是否必填：
        <el-radio-group v-model="item.necReason" size="small">
          <el-radio-button :label="1">是</el-radio-button>
          <el-radio-button :label="0">否</el-radio-button>
        </el-radio-group>
        <!-- <el-switch v-model="item.necReason" active-color="#13ce66"></el-switch> -->
      </p>
    </el-col>
  </el-row>
</template>

<script>
import { levelAll } from '@/api/satisfaction'
export default {
  data() {
    return {
      levelList: [],
      type: this.$route.params.type
    }
  },
  methods: {
    setArr(arr) {
      if (arr.length > 0) {
        arr.map(v => {
          v.check = true
        })
        this.levelList = [...arr]
      }
    },
    postData() {
      console.log('5 步进入postData')

      let arr = []
      this.levelList.map(v => {
        if (v.check) {
          arr.push(v)
        }
      })
      if (arr.length > 0) {
        let submit = arr.every(v => v.levelScore || v.levelScore === 0)
        if (submit) {
          this.$emit('postData', true, arr, 5)
        } else {
          this.$message.error('勾选项必须填写对应分数')
          this.$emit('notSubmit', 5)
        }
      } else {
        this.$emit('notSubmit', 5)
        this.$message.error('请选择考评等级')
      }
    }
  },
  created() {
    console.log('five comp type', this.type)

    if (this.type === 'add') {
      // 新增才调用，复制新增不调用
      levelAll().then(res => {
        console.log('res', res)
        this.levelList = res.data
      })
    }
  }
}
</script>
